<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>添加课程</title>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

</head>
<style>
    #my-sub-student{
        margin-top: 50px;
    }
</style>
<body>



<div class="container ">
    <!--<div class="row justify-content-md-center">-->
        <!--<a href="/index"><img class="mb-4" th:src="@{/images/index/favicon.png}" alt="" width="72" height="72"></a>-->
    <!--</div>-->
    <h1 class="text-center h3 mb-3 font-weight-normal" th:text="${test}">添加课程</h1>
    <div id="addStudentForm">
        <div class="row justify-content-md-center">
            <div class="col-6 form-group">
                <label for="teacherCourse" >课程名字</label>
                <input type="text" class="form-control" id="teacherCourse" required>
                <div class="invalid-feedback">
                    课程名字不得为空
                </div>
            </div>

        </div>

        <div class="row justify-content-md-center">
            <div class="col-6">
                <div class="form-group">
                    <label for="studentClass">班级</label>
                    <select class="form-control" id="studentClass">
                        <option value="1">电气信息工程学院-自动化专业-16自动化</option>
                        <option value="2">电气信息工程学院-自动化专业-17自动化</option>
                        <option value="3">电气信息工程学院-自动化专业-18自动化</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="row justify-content-md-center">
            <div class="col-6">
                <div class="form-group">
                    <label for="trueTeacherId">老师</label>
                    <select class="form-control" id="trueTeacherId" >
                        <option value="100101">丁仲</option>
                        <option value="100202">于海</option>
                        <option value="100301">庄玲</option>
                        <option value="100402">汪禄</option>
                        <option value="100501">奚庆</option>
                    </select>
                </div>
            </div>
        </div>


        <div class="row justify-content-md-center">
            <div class="col-6 form-group">
                <label for="teacherBatch">课程批次</label>
                <input type="text" class="form-control" id="teacherBatch" value="2018-2019学年第一学期">

            </div>
        </div>

        <div class="row justify-content-md-center">
            <div class="col-6">
                <div class="form-group">
                    <label for="teacherDepartment">所属部门</label>
                    <select class="form-control" id="teacherDepartment">
                        <option value="理学院">理学院</option>
                        <option value="电气信息工程学院">电气信息工程学院</option>
                        <option value="外国语学院">外国语学院</option>
                        <option value="人文学院">人文学院</option>
                        <option value="体育教学部">体育教学部</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="row justify-content-md-center">

            <div class="col-6">
                <div class="form-group">
                    <label for="teacherCourseClassification">课程分类</label>
                    <select class="form-control" id="teacherCourseClassification">
                        <option value="理论">理论</option>
                        <option value="体育">体育</option>

                    </select>
                </div>
            </div>

        </div>

        <div class="row justify-content-md-center">
            <div class="col-6 form-group">
                <label for="teacherParticipant" >参评对象</label>
                <input type="text" class="form-control" id="teacherParticipant" value="学生" disabled="disabled">

            </div>

        </div>


        <div class="row justify-content-md-center">
            <div class="col-4">
                <button class="btn btn-primary btn-lg btn-block" id="my-sub-student">提交</button>
                <!--<button class="btn btn-primary btn-lg btn-block" id="formSub">提交</button>-->
            </div>
        </div>
    </div>

</div>

<div class="modal fade" id="successModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">添加学生提示</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <p>恭喜你！添加成功</p>
            </div>
            <div class="modal-footer">
                <!--<button type="button" class="btn btn-warning"><a href="/tourist_login">前去登陆</a></button>-->
                <button type="button" class="btn btn-primary" data-dismiss="modal">确定</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="errorModal" tabindex="-1" role="dialog" aria-labelledby="errorModalTitle" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="errorModalTitle">添加课程提示</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <p>课程添加错误</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-warning"><a href="/error">反馈</a></button>
                <button type="button" class="btn btn-primary" id="sure-add" data-dismiss="modal">确定</button>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">

    $(document).ready(function () {
        var myDate = new Date;
        var year = myDate.getFullYear(); //获取当前年
        var mon = myDate.getMonth() + 1; //获取当前月

        var batch = "";
        if(1< mon < 9){
            // 下学期
            batch = (year-1)+"-"+year+"学年第二学期";
        }else {
            batch = year+"-"+(year+1)+"学年第一学期";
        }
        console.log(batch);
        $("#teacherBatch").val(batch);

        // 2018-2019学年第一学期

        $("#my-sub-student").click(function (event) {

            // var $form = $("#addStudentForm");
            // if($form[0].checkValidity()===false){
            //     event.preventDefault();
            //     event.stopPropagation();
            //
            //     $form.addClass("was-validated");
            //     return;
            // }


            var data = {
                teacherBatch:$("#teacherBatch").val(),
                trueTeacherId:$("#trueTeacherId").val(),
                teacherDepartment:$("#teacherDepartment").val(),
                teacherCourse:$("#teacherCourse").val(),
                teacherCourseClassification:$("#teacherCourseClassification").val(),
                teacherParticipant:$("#teacherParticipant").val(),
                studentClass:$("#studentClass").val()

            };

            $.ajax({
                type:"post",
                url:"/ManagerController/addCourse",
                data:JSON.stringify(data),
                datatype:"json",
                contentType:'application/json',
                async:true,
                success:function (res) {
                    var result = eval('('+res+')');
                    console.log(result.value);
                    if (result.value=="success"){
                        $('#successModal').modal("show");
                    }else {
                        $('#errorModal').modal("show");
                    }
                },
                error:function (XMLHttpRequest, textStatus, errorThrown) {
                    // $("#msg-span").html("添加失败，出现错误:"+textStatus);
                    $('#errorModal').modal("show");
                }
            })
        });

        //清空表单
        $("#sure-add").click(function () {
            $("#addStudentForm").val("")
        });


    })
</script>
</body>
</html>